package com.study.controller;

import com.study.service.NacosClientService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/nacos-client")
public class NacosClientController {

    private NacosClientService nacosClientService;

    //构造方法注入
    public NacosClientController(NacosClientService nacosClientService){
        this.nacosClientService = nacosClientService;
    }

    /**
     * 根据 serive id 获取服务所有的实例信息
     * @param serviceId
     * @return
     */
    @GetMapping("/service-instance")
    public List<ServiceInstance> logNacosClientInfo(@RequestParam(defaultValue = "ecommerce-nacos-client") String serviceId){

        log.info("coming in log nacos client info: [{}]", serviceId);

        return nacosClientService.getNacosClientInfo(serviceId);

    }


}
